package top.hkyzf.study.leetcode.math;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2022-3-3 9:02
 */
public class 各位相加_258 {
    public int addDigits(int num) {
        if (num < 10) {
            return num;
        }
        int newNum = num / 10;
        int result = num % 10;
        while (newNum > 0) {
            result += newNum % 10;
            newNum = newNum / 10;
        }
        return addDigits(result);
    }

    @Test
    public void testAddDigits () {
        int num = 38;
        System.out.println(addDigits(num));
    }
}
